$(function () {
    findUniversity();
    findEducation();
    findByUserName();
});

function findUniversity() {
    let result = myAjax('/university/selectAll', "post", {})
    let html = "<option value=''>请选择院校</option>";
    for (let i = 0; i < result.list.length; i++) {
        html += '<option value="' + result.list[i].id + '">' + result.list[i].academy + '</option>'
    }
    $("#university").html(html);
}

function findEducation() {
    let result = myAjax('/education/selectAll', "post", {})
    let html = "<option value=''>请选择学历</option>";
    for (let i = 0; i < result.length; i++) {
        html += '<option value="' + result[i].id + '">' + result[i].category + '</option>'
    }
    $("#education").html(html);
}

function findByUserName() {
    let data = {
        username: sessionStorage.getItem("user-name"),
    }
    let result = myAjax('/user/findByUserName', 'post', data);
    show(result);
}

function show(data) {
    $("#username").val(data.username);
    $("#name").val(data.name);
    $("#age").val(data.age);
    $("input[name='sex'][value=" + data.sex + "]").attr("checked", true);
    $("#phone").val(data.phone);
    $('#university option').filter(function () {
        return $(this).text() == data.graduate;
    }).prop("selected", true);
    $('#education option').filter(function () {
        return $(this).text() == data.education;
    }).prop("selected", true);
    if (data.state == 1) {
        $("input:checkbox[value='1']").attr('checked', 'true');
    }
    $("#registerTime").val(data.registrationTime);
    $("#address").val(data.address);
}